import express from "express";
import { PORT } from "./src/config/config.default";
import router from "@router";
import morgan from "morgan";
import cors from "cors";
import errorHandler from "@middleware/error-handler";
import "@model" // 连接数据库

const app = express();

// morgan 日志中间件
app.use(morgan("dev"));

// json 解析
app.use(express.json());

// x-www-form-urlencoded 解析
app.use(express.urlencoded({ extended: true }));

// 跨域 cors
app.use(cors());

// 挂载路由
app.use(router);

// 错误处理
app.use(errorHandler());

app.listen(PORT, () => {
  console.log(`server listen on http://localhost:${PORT}`);
});
